home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / hplip / ui / choosedevicedlg.py < prev    next >
Text File  |  2008-10-13  |  4KB  |  108 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. from base.g import *
  23. import sys
  24. from qt import *
  25.  
  26. class ChooseDeviceDlg(QDialog):
  27.     def __init__(self, devices, parent = None,name = None,modal = 0,fl = 0):
  28.         QDialog.__init__(self,parent,name,modal,fl)
  29.  
  30.         if not name:
  31.             self.setName("ChooseDeviceDlg")
  32.  
  33.         self.device_uri = ''
  34.  
  35.         ChooseDeviceDlg_Layout = QGridLayout(self,1,1,6,6,"ChooseDeviceDlg_Layout")
  36.  
  37.         self.OKButton = QPushButton(self,"OKButton")
  38.  
  39.         ChooseDeviceDlg_Layout.addWidget(self.OKButton,2,2)
  40.  
  41.         self.CancelButton = QPushButton(self,"CancelButton")
  42.  
  43.         ChooseDeviceDlg_Layout.addWidget(self.CancelButton,2,1)
  44.         spacer1 = QSpacerItem(391,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  45.         ChooseDeviceDlg_Layout.addItem(spacer1,2,0)
  46.         spacer2 = QSpacerItem(20,290,QSizePolicy.Minimum,QSizePolicy.Expanding)
  47.         ChooseDeviceDlg_Layout.addItem(spacer2,1,0)
  48.  
  49.         self.DevicesButtonGroup = QButtonGroup(self,"DevicesButtonGroup")
  50.         self.DevicesButtonGroup.setColumnLayout(0,Qt.Vertical)
  51.         self.DevicesButtonGroup.layout().setSpacing(6)
  52.         self.DevicesButtonGroup.layout().setMargin(6)
  53.         DevicesButtonGroupLayout = QGridLayout(self.DevicesButtonGroup.layout())
  54.         DevicesButtonGroupLayout.setAlignment(Qt.AlignTop)
  55.  
  56.         self.radio_buttons = {}
  57.         
  58.         last_used_device_uri = user_cfg.last_used.device_uri
  59.         last_used_index = None
  60.  
  61.         for y in range(len(devices)):
  62.             self.radio_buttons[y] = QRadioButton(self.DevicesButtonGroup,"radioButton%d" % y)
  63.             self.radio_buttons[y].setText(devices[y][0])
  64.             
  65.             if devices[y][0] == last_used_device_uri:
  66.                 last_used_index = y
  67.                 self.device_uri = devices[y][0]
  68.             
  69.             DevicesButtonGroupLayout.addWidget(self.radio_buttons[y], y, 0)
  70.  
  71.         if last_used_index is not None:
  72.             self.radio_buttons[last_used_index].setChecked(1)
  73.         else:
  74.             self.radio_buttons[0].setChecked(1)
  75.             self.device_uri = devices[0][0]
  76.             
  77.         ChooseDeviceDlg_Layout.addMultiCellWidget(self.DevicesButtonGroup,0,0,0,2)
  78.  
  79.         self.languageChange()
  80.  
  81.         self.resize(QSize(592,112).expandedTo(self.minimumSizeHint()))
  82.         self.clearWState(Qt.WState_Polished)
  83.  
  84.         self.connect(self.OKButton,SIGNAL("clicked()"),self,SLOT("accept()"))
  85.         self.connect(self.CancelButton,SIGNAL("clicked()"),self,SLOT("reject()"))
  86.         self.connect(self.DevicesButtonGroup,SIGNAL("clicked(int)"),self.DevicesButtonGroup_clicked)
  87.  
  88.     def languageChange(self):
  89.         self.setCaption(self.__tr("Choose Device"))
  90.         self.OKButton.setText(self.__tr("OK"))
  91.         self.CancelButton.setText(self.__tr("Cancel"))
  92.         self.DevicesButtonGroup.setTitle(self.__tr("Available Devices:"))
  93.  
  94.  
  95.     def __tr(self,s,c = None):
  96.         return qApp.translate("ChooseDeviceDlg",s,c)
  97.  
  98.     def DevicesButtonGroup_clicked(self,a0):
  99.         self.device_uri = unicode(self.radio_buttons[a0].text())
  100.  
  101. if __name__ == "__main__":
  102.     a = QApplication(sys.argv)
  103.     QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
  104.     w = ChooseDeviceDlg()
  105.     a.setMainWidget(w)
  106.     w.show()
  107.     a.exec_loop()
  108.